#pragma strict
import System.Collections.Generic;
//////////////////////////////////////////////////////
///工程,下载的资源管理
///AssetBundle字典. 
///url为key,value:AssetBundle
//////////////////////////////////////////////////////
class AssetBundleDictionary{
	/** 资源字典.*/
	private static var dict:Dictionary.<String,AssetBundle> = new Dictionary.<String,AssetBundle>();
	/** 添加资源. */
	static function Add(url:String,go:AssetBundle){
		Remove(url);
		dict.Add(url,go);
	}
	/** 移除指定的资源. */
	static function Remove(url:String){
		if(Contains(url)){
			if(dict[url])
				dict[url].Unload(true);
			dict.Remove(url);
		}
	}
	/** 测试移除无效的资源. */
	static function RemoveInvalid(url:String){
		if(Contains(url)){
			if(! dict[url]){
				dict.Remove(url);
			}
		}
	}
	/** 清除全部资源. */
	static function Clear(){
		for(var ab:AssetBundle in dict.Values){
			ab.Unload(true);
		}
		dict.Clear();
	}
	
	/** 根据key获取一个AssetBundle */
	static function Get(url:String):AssetBundle{
		if(Contains(url))
			return dict[url];
		return null;
	}
	/** 从 字典中获取 mainAsset */
	static function GetMainAsset(url:String):Object{
		if(Contains(url)){
			return dict[url].mainAsset;
		}
		return null;
	}
	/** 字典中是否包含key */
	static function Contains(url:String):boolean{
		return dict.ContainsKey(url);
	}
}